一个好用的工业通信组件,支持主流PLC通信等。
HslCommunication // 接收数据
byte[] buffer = null;
byte[] data = new byte[2048];
int receiveCount = 0;
while (true)
{
System.Threading.Thread.Sleep( 20 );
if(SP_ReadData.BytesToRead < 1)
{
buffer = new byte[receiveCount];
Array.Copy( data, 0, buffer, 0, receiveCount );
break;
}
receiveCount = SP_ReadData.Read( data, receiveCount, SP_ReadData.BytesToRead );
}
评论